assertEquals( $shouldMatch, ParserOutput::isLinkInternal( $server, $url ) );
}
/**
* @covers ParserOutput::setExtensionData
* @covers ParserOutput::getExtensionData
*/
public function testExtensionData() {
$po = new ParserOutput();
$po->setExtensionData( "one", "Foo" );
$this->assertEquals( "Foo", $po->getExtensionData( "one" ) );
$this->assertNull( $po->getExtensionData( "spam" ) );
$po->setExtensionData( "two", "Bar" );
$this->assertEquals( "Foo", $po->getExtensionData( "one" ) );
$this->assertEquals( "Bar", $po->getExtensionData( "two" ) );
$po->setExtensionData( "one", null );
$this->assertNull( $po->getExtensionData( "one" ) );
$this->assertEquals( "Bar", $po->getExtensionData( "two" ) );
}
/**
* @covers ParserOutput::setProperty
* @covers ParserOutput::getProperty
* @covers ParserOutput::unsetProperty
* @covers ParserOutput::getProperties
*/
public function testProperties() {
$po = new ParserOutput();
$po->setProperty( 'foo', 'val' );
$properties = $po->getProperties();
$this->assertEquals( $po->getProperty( 'foo' ), 'val' );
$this->assertEquals( $properties['foo'], 'val' );
$po->setProperty( 'foo', 'second val' );
$properties = $po->getProperties();
$this->assertEquals( $po->getProperty( 'foo' ), 'second val' );
$this->assertEquals( $properties['foo'], 'second val' );
$po->unsetProperty( 'foo' );
$properties = $po->getProperties();
$this->assertEquals( $po->getProperty( 'foo' ), false );
$this->assertArrayNotHasKey( 'foo', $properties );
}
/**
* @covers ParserOutput::getText
* @dataProvider provideGetText
* @param array $options Options to getText()
* @param array $poState ParserOptions state fields to set
* @param string $text Parser text
* @param string $expect Expected output
*/
public function testGetText( $options, $poState, $text, $expect ) {
$this->setMwGlobals( [
'wgArticlePath' => '/wiki/$1',
'wgScriptPath' => '/w',
'wgScript' => '/w/index.php',
] );
$po = new ParserOutput( $text );
// Emulate Parser
$po->setEditSectionTokens( true );
if ( $poState ) {
$wrap = TestingAccessWrapper::newFromObject( $po );
foreach ( $poState as $key => $value ) {
$wrap->$key = $value;
}
}
$actual = $po->getText( $options );
$this->assertSame( $expect, $actual );
}
public static function provideGetText() {
// phpcs:disable Generic.Files.LineLength
$text = <<
One
Two
Two point one
Three
EOF; return [ 'No stateless options, default state' => [ [], [], $text, <<One
Two
Two point one
Three
EOF ], 'No stateless options, TOC statefully disabled' => [ [], [ 'mTOCEnabled' => false ], $text, <<One
Two
Two point one
Three
EOF ], 'No stateless options, section edits statefully disabled' => [ [], [ 'mEditSectionTokens' => false ], $text, <<One
Two
Two point one
Three
EOF ], 'Stateless options override stateful settings' => [ [ 'allowTOC' => true, 'enableSectionEditLinks' => true ], [ 'mTOCEnabled' => false, 'mEditSectionTokens' => false ], $text, <<One
Two
Two point one
Three
EOF ], 'Statelessly disable section edit links' => [ [ 'enableSectionEditLinks' => false ], [], $text, <<One
Two
Two point one
Three
EOF ], 'Statelessly disable TOC' => [ [ 'allowTOC' => false ], [], $text, <<One
Two
Two point one
Three
EOF ], ]; // phpcs:enable } }